#include <iostream>
#include <string>
#include <vector>

bool isPrime(int num) {
    if(num < 2) {
        return false;
    }
    for(int i = 2; i*i <= num; i++) {
        if(num % i == 0) {
            return false;
        }
    }
    return true;
}

int main() {
    std::vector<std::string> words = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
    std::string word1, word2, word3;
    std::cin >> word1 >> word2 >> word3;
    
    std::string number_str = "";
    for(int i = 0; i < words.size(); i++) {
        if(word1 == words[i]) {
            number_str += std::to_string(i);
        }
        if(word2 == words[i]) {
            number_str += std::to_string(i);
        }
        if(word3 == words[i]) {
            number_str += std::to_string(i);
        }
    }
    
    if(number_str.size() != 3 || number_str[0] == '0') {
        std::cout << "Wrong input" << std::endl;
        return 0;
    }
    
    int number = std::stoi(number_str);
    
    int prime1 = number;
    int prime2 = number;
    
    while(!isPrime(prime1)) {
        prime1++;
    }
    
    while(!isPrime(prime2)) {
        prime2--;
    }
    
    if(prime1 - number <= number - prime2) {
        std::cout << prime1 << std::endl;
    } else {
        std::cout << prime2 << std::endl;
    }
    
    return 0;
}